import React, { Component } from 'react';

class Demo extends Component {

  state = {count: 0}

  add = () => {
    // 1_对象式setState
    // const {count} = this.state
    // this.setState ({count: count +1}, () => {
    //   console.log (this.state.count)
    // })

    // 2_函数式
    this.setState ((state, props) => {
      // console.log (state, props)
      return {count: state.count + 1}
    })
  }

  render() {
    return (
      <div>
        <h2>当前求和为： {this.state.count}</h2>
        <button onClick={this.add}>+1</button>
      </div>
    );
  }
}

export default Demo;
